import { snippets } from "@/lib/generated/snippets";
import { Snippet } from "@/components/code";
import { Callout, Card, Cards, Steps, Tabs } from "nextra/components";
import UniversalTabs from "@/components/UniversalTabs";

## Durable Events

Durable events are a feature of **durable tasks** which allow tasks to wait for an event to occur before continuing. This is useful in cases where a task needs to wait for a long time for an external action. Durable events are useful, because even if your task is interrupted and requeued while waiting for an event, the event will still be processed. When the task is resumed, it will read the event from the durable event log and continue processing.

## Declaring durable events

Durable events are declared using the context method `WaitFor` (or utility method `WaitForEvent`) on the `DurableContext` object.

<UniversalTabs items={["Python", "Typescript", "Go"]}>
  <Tabs.Tab title="Python">

<Snippet src={snippets.python.durable_event.worker.durable_event} />

</Tabs.Tab>
<Tabs.Tab title="Typescript">

<Snippet src={snippets.typescript.durable_event.workflow.durable_event} />

</Tabs.Tab>
<Tabs.Tab title="Go">

<Snippet src={snippets.go.durable.event.main.durable_event} />

</Tabs.Tab>
</UniversalTabs>

## Durable event filters

Durable events can be filtered using [CEL](https://github.com/google/cel-spec) expressions. For example, to only receive `user:update` events for a specific user, you can use the following filter:

<UniversalTabs items={["Python", "Typescript", "Go"]}>
  <Tabs.Tab title="Python">

<Snippet src={snippets.python.durable_event.worker.durable_event_with_filter} />

</Tabs.Tab>
<Tabs.Tab title="Typescript">

<Snippet
  src={snippets.typescript.durable_event.workflow.durable_event_with_filter}
/>

</Tabs.Tab>
<Tabs.Tab title="Go">

<Snippet src={snippets.go.durable.event.main.durable_event_with_filter} />

</Tabs.Tab>
</UniversalTabs>
